<template>
  <div>
    <el-tree-select v-model="props.value" :data="classOptions" :default-expand-all="true"
      :filter-node-method="filterNodeMethod" :render-after-expand="false" check-strictly filterable placeholder="请选择药品类型"
      clearable style="width: 100%;" @node-click="classNodeClick" />
  </div>
</template>

<script setup lang="ts">
import { listDrugClassDict } from "@/api/drug/drugClassDict";

const { proxy } = getCurrentInstance() as any
const emits = defineEmits(["orgNodeClick", "getDrugClassTreeEmits"])
// 下拉框机构树
let classOptions = ref<any>([])
const props = defineProps({
  value: {
    type: String,
    default: ''
  }
})
/** 检索过滤 */
const filterNodeMethod = (value, data) => data.label.includes(value)

onMounted(() => {
  getDrugClassTree()
})

function classNodeClick(data, _e) {
  emits("orgNodeClick", data)
}


/** 查询药品类型下拉树结构 */
function getDrugClassTree() {
  listDrugClassDict({ 'delFlag': '0' }).then(response => {
    classOptions.value = [{
      id: 0, label: '顶级节点', value: 0, className: "顶级节点",
      children: proxy.$handleTree(response.data, "id", "className")
    }];
    emits("getDrugClassTreeEmits", response);
  })
}
</script>

<style scoped></style>
